<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="./vue.js"></script>
</head>
<body>
  <div id="app">
    姓：<input type="text" v-model="xing">
    名：<input type="text" v-model="ming">
    姓名：<input type="text" v-model="username">

  </div>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        xing: '',
        ming: ''
      },
      computed: {
        username: {
          set (value) {
            // 修改username的时候就会走set，参数就是修改之后的值
            console.log(value)
            this.xing = value.slice(0, 1)
            this.ming = value.slice(1)
          },
          get () {
            return this.xing + this.ming
          }
        }
      }
    })
  </script>
</body>
</html>
